package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.common.dto.AttachmentDto;
import com.koron.css2.common.service.AbstractExportExcel;
import com.koron.css2.newProjectCenter.bean.PjMaterialBean;
import com.koron.css2.newProjectCenter.bean.query.PjMaterialQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjMaterialMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 工程材料列表数据导出
 */
public class PjMaterialExport extends AbstractExportExcel {

    private static Logger logger = LoggerFactory.getLogger(PjMaterialExport.class);

    @Override
    public AttachmentDto getAttachment(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        List<PjMaterialBean> pjMaterialList = new ArrayList<>();
        try {
            PjMaterialQueryBean pjMaterialQuery = JsonUtils.objectToPojo(req.getData(), PjMaterialQueryBean.class);
            PjMaterialMapper pjMaterialMapper = factory.getMapper(PjMaterialMapper.class);
            pjMaterialList = pjMaterialMapper.selectList(pjMaterialQuery);
            for (PjMaterialBean pjMaterial : pjMaterialList){
                if (pjMaterial.getStatus() == 1){
                    pjMaterial.setStatusName("启用");
                }
                if (pjMaterial.getStatus() == 0){
                    pjMaterial.setStatusName("停用");
                }
            }
        }catch (Exception ex){
            logger.error("材料列表数据查询失败:" + ex);
        }
        AttachmentDto attachment = new AttachmentDto();
        attachment.setBtlTemplate("PjMaterialExport.btl");
        attachment.setData(pjMaterialList);
        attachment.setFilename("工程材料导出");
        attachment.setFileTemplate("PjMaterialExport.xlsx");
        attachment.setFileType("excel");
        return attachment;
    }

}
